package com.example.ui.learn;

import java.text.DecimalFormat;
import java.util.Timer;

import com.example.downloadmanager.DownloadInfo;
import com.example.huashangapp.R;
import com.example.ui.leftmenu.DownItem;
import com.example.ui.leftmenu.Itme10View;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
import android.widget.Toast;

public class DownHandler extends Handler {

	Boolean isOne=false;
	int count=0; 
	int delete=0;
	int ThreadId=0;
	int compeleteSize=0;
	String urlstr;
	public DownHandler(){
	
	}
	
	@Override
	public void dispatchMessage(Message msg) {
		
		super.dispatchMessage(msg);
	}

	@Override
	public String getMessageName(Message message) {
		
		return super.getMessageName(message);
	}
	@SuppressWarnings("static-access")
	@Override
	public  void handleMessage(Message msg) {
		DownItem downItem = null;
		
		switch (msg.what) {
		case 0:
			if(msg.obj!=null){
				downItem=DownUtils.listDownItem.get(msg.obj.toString());
				if(downItem==null){
					break;
				}
				downItem.getPd_progressBar().setMax(downItem.getFileSize());
				downItem.getPd_progressBar().setProgress(downItem.getDownLoadFileSize());
				String b=new  DecimalFormat("##.#").format(downItem.getFileSize()/1024/1024);
				downItem.getJindu().setText(b+"M");
				downItem.getBai().setText((int)(downItem.getDownLoadFileSize()*100.0f/downItem.getFileSize())+"%");
				
			}
			break;
		case 1:
			if(msg.obj!=null){
			String urlstr=(String)msg.obj;
			DownItem di=DownUtils.listDownItem.get(urlstr);
			DownUtils.downIngCount--;
			DownUtils.listUrl.add(urlstr);
			DownUtils.listDowned.put(urlstr,di);
			DownUtils.downUrl.remove(urlstr);
			DownUtils.listDownItem.remove(di);
			}
			Itme10View.down_list.setAdapter(DownUtils.adapter);
			DownUtils.adapter.notifyDataSetChanged();
			break;
		}
		super.handleMessage(msg);
	}
	@Override
	public  boolean sendMessageAtTime(Message msg, long uptimeMillis) {
		
		return super.sendMessageAtTime(msg, uptimeMillis);
	}
	

	@Override
	public String toString() {
		
		return super.toString();
	}

}
